import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dell
 * Date: 2024-01-08
 * Time: 19:07
 */
public class MyStack {
    int[] arr;
    int unsize;

    public MyStack() {
        this.arr=new int[5];
    }
    public void push(int data){
        if (isfull()){
            arr=Arrays.copyOf(arr,2*arr.length);
        }
        arr[unsize] = data;
        unsize++;
    }
    public boolean isfull(){
        return unsize==arr.length;
    }
    public boolean iskong(){
        return  unsize==0;
    }
    public int pop(){
        if (iskong()){
            throw new StackException("数组空异常");
        }
        unsize--;
        return arr[unsize];
    }
    public int peek(){
        if (iskong()) {
            throw new StackException("数组空异常");
        }
        return arr[unsize-1];
    }
}